var e = require("../../../@babel/runtime/helpers/interopRequireDefault").default;

require("../../../@babel/runtime/helpers/Arrayincludes");

var t = require("../../../@babel/runtime/helpers/regeneratorRuntime"), i = require("../../../@babel/runtime/helpers/asyncToGenerator"), a = e(require("../../../api/superMemberGold.js")), n = e(require("../../../utils/regs.js")), s = e(require("../../../libs/wxsubscribe/index")), o = getApp();

Page({
    data: {
        showPage: !1,
        showBindPhoneDialog: !1,
        bindPhoneTips: "您还未绑定王卡助手小程序，请使用王卡号码绑定",
        vipType: "",
        serialNumber: "",
        productName: "",
        getRightAccount: "",
        getRightAccountConfirm: "",
        accountDisable: !1,
        activeActionCode: "",
        activeRightType: "",
        showRights: !1,
        showConfirm: !1,
        show100minConfirm: !1,
        activeRightIndex: -1,
        tempRightIndex: -1,
        pkgList: [],
        rightList: []
    },
    onLoad: function(e) {
        this.getUserInfo();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    getUserInfo: function() {
        var e = this;
        return i(t().mark(function i() {
            var n, s, o, r, c, u, h, d, g;
            return t().wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return wx.showLoading({
                        title: "加载中..."
                    }), t.prev = 1, t.next = 4, a.default.getUserInfo();

                  case 4:
                    n = t.sent, s = n.code, o = n.message, r = n.data, c = r.hasReceiveRightThisMonth, 
                    u = r.vipStatus, h = r.vipType, d = r.serialNumber, g = r.productName, wx.hideLoading(), 
                    s + "" == "20001" ? u + "" != "03" ? c ? wx.redirectTo({
                        url: "/pages/superMemberGold/success/success"
                    }) : (e.setData({
                        showPage: !0,
                        vipType: h,
                        serialNumber: d,
                        productName: g
                    }), e.getRightList(h)) : e.setData({
                        showBindPhoneDialog: !0,
                        bindPhoneTips: "尊敬的王上，超级会员生效才能领取互联网权益哦~"
                    }) : e.setData({
                        showBindPhoneDialog: !0,
                        bindPhoneTips: o || "请求失败，请稍后再试！"
                    }), t.next = 21;
                    break;

                  case 17:
                    t.prev = 17, t.t0 = t.catch(1), wx.hideLoading(), e.setData({
                        showBindPhoneDialog: !0,
                        bindPhoneTips: t.t0.message || t.t0.msg || "请求失败，请稍后再试！"
                    });

                  case 21:
                  case "end":
                    return t.stop();
                }
            }, i, null, [ [ 1, 17 ] ]);
        }))();
    },
    afterBindPhone: function() {
        this.setData({
            showBindPhoneDialog: !1
        }), this.getUserInfo();
    },
    getRightList: function(e) {
        var n = this;
        return i(t().mark(function i() {
            var s, o, r, c;
            return t().wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return t.prev = 0, t.next = 3, a.default.getRightList({
                        vipType: e
                    });

                  case 3:
                    s = t.sent, o = s.data, r = [], o.sort(function(e, t) {
                        return e.order - t.order;
                    }), (c = o.find(function(e) {
                        return "教育权益包" === e.name;
                    })) && (r = c.innerRightList), n.setData({
                        rightList: o,
                        eduList: r
                    }), getApp().globalData.rightList = o, t.next = 16;
                    break;

                  case 13:
                    t.prev = 13, t.t0 = t.catch(0), wx.showModal({
                        title: "温馨提示",
                        content: t.t0.message || t.t0.msg || "请求失败，请稍后再试！",
                        showCancel: !1
                    });

                  case 16:
                  case "end":
                    return t.stop();
                }
            }, i, null, [ [ 0, 13 ] ]);
        }))();
    },
    clickChooseVip: function() {
        this.setData({
            showRights: !0,
            tempRightIndex: this.data.activeRightIndex
        });
    },
    onChooseRights: function(e) {
        var t = this;
        switch (this.setData({
            tempRightIndex: e.detail
        }), !0) {
          case this.data.rightList[e.detail].name.indexOf("教育权益包") > -1:
            wx.navigateTo({
                url: "/pages/superMemberGold/eduPkgList/eduPkgList",
                events: {
                    select: function(e) {
                        if (e) {
                            var i = t.data.rightList.findIndex(function(e) {
                                return e.name.includes("教育");
                            });
                            t.setData({
                                activeActionCode: e,
                                tempRightIndex: i
                            }), wx.nextTick(function() {
                                t.onConfirmRights(), setTimeout(function() {
                                    wx.pageScrollTo({
                                        duration: 0,
                                        scrollTop: 0
                                    });
                                }, 50);
                            });
                        }
                    }
                },
                success: function(e) {
                    var i = t.data.rightList.find(function(e) {
                        return "教育权益包" === e.name;
                    });
                    i && e.eventChannel.emit("eduList", {
                        actionCode: t.data.activeActionCode,
                        list: i.innerRightList
                    });
                }
            });
            break;

          case this.data.rightList[e.detail].name.indexOf("星巴克") > -1:
            wx.navigateTo({
                url: "/pages/superMemberGold/rightDetail/rightDetail?type=starbuck",
                events: {
                    select: function(e) {
                        e && t.onConfirmRights();
                    }
                }
            });
            break;

          case this.data.rightList[e.detail].name.indexOf("美团外卖") > -1:
            wx.navigateTo({
                url: "/pages/superMemberGold/rightDetail/rightDetail?type=meituan",
                events: {
                    select: function(e) {
                        e && t.onConfirmRights();
                    }
                }
            });
        }
    },
    onConfirmRights: function() {
        var e = this;
        this.setData({
            activeRightIndex: this.data.tempRightIndex,
            showRights: !1
        }), wx.nextTick(function() {
            var t = e.data.rightList[e.data.activeRightIndex], i = t.name, a = t.type, n = t.actionCode, s = e.setAccountDisable();
            e.setData({
                accountDisable: s,
                activeRightType: a,
                activeActionCode: i.includes("教育") ? e.data.activeActionCode : n,
                getRightAccount: s ? e.data.serialNumber : "",
                getRightAccountConfirm: ""
            });
        });
    },
    setAccountDisable: function() {
        var e = this.data.activeRightIndex, t = this.data.rightList, i = t[e].name, a = t[e].type;
        switch (!0) {
          case e > -1 && i.includes("喜马拉雅"):
          case e > -1 && "教育权益包" === i:
          case e > -1 && i.includes("星巴克"):
          case e > -1 && i.includes("美团外卖"):
          case e > -1 && "100分钟全国语音" === i:
          case e > -1 && "腾讯视频VIP" === i && "phone" === a:
            return !0;

          case -1 === e:
          default:
            return !1;
        }
    },
    turnToDetail: function(e) {
        var t = this, i = e.currentTarget.dataset.type;
        switch (i) {
          case "starbuck":
          case "meituan":
            var a;
            "starbuck" === i && (a = this.data.rightList.find(function(e) {
                return e.name.includes("星巴克");
            })), "meituan" === i && (a = this.data.rightList.find(function(e) {
                return e.name.includes("美团");
            }));
            var n = a.exhausted ? "1" : "0";
            wx.navigateTo({
                url: "/pages/superMemberGold/rightDetail/rightDetail?exhausted=" + n + "&type=" + i,
                events: {
                    select: function(e) {
                        var a;
                        e && ("starbuck" === i && (a = t.data.rightList.findIndex(function(e) {
                            return e.name.includes("星巴克");
                        })), "meituan" === i && (a = t.data.rightList.findIndex(function(e) {
                            return e.name.includes("美团");
                        })), t.setData({
                            tempRightIndex: a
                        }), wx.nextTick(function() {
                            t.onConfirmRights(), setTimeout(function() {
                                wx.pageScrollTo({
                                    duration: 0,
                                    scrollTop: 0
                                });
                            }, 50);
                        }));
                    }
                }
            });
            break;

          default:
            wx.navigateTo({
                url: "/pages/superMemberGold/eduDetail/eduDetail?actionCode=" + i
            });
        }
    },
    clickGetRight: function() {
        if (-1 !== this.data.activeRightIndex) {
            if (this.testAccount()) if (this.data.accountDisable || this.data.getRightAccount === this.data.getRightAccountConfirm) {
                var e = this;
                new s.default({
                    env: "miniprogram",
                    cookie: o.globalData.token,
                    templateId: "Kbj2Be_BX0eyf32vYSu-n71pdVdRaGp4GxVYl7WrRSE",
                    seq: Date.now(),
                    action_id: "kcardSuperVip",
                    scene: "",
                    extra_data: "",
                    success: function(t, i) {
                        var a = new Date();
                        "100分钟全国语音" === e.data.rightList[e.data.activeRightIndex].name && a.getDate() >= 15 ? e.setData({
                            show100minConfirm: !0
                        }) : e.setData({
                            showConfirm: !0
                        });
                    },
                    error: function(e) {
                        wx.showModal({
                            title: "温馨提示",
                            content: e.msg || e.message || "操作失败，请稍后再试!",
                            showCancel: !1
                        });
                    }
                });
            } else wx.showModal({
                content: "两遍输入账号不相同，请检查并重新输入",
                showCancel: !1
            });
        } else wx.showToast({
            title: "请选择互联网会员权益",
            icon: "none"
        });
    },
    testAccount: function() {
        var e = this.data.getRightAccount, t = "";
        switch (this.data.activeRightType) {
          case "qq":
            n.default.qq.test(e) || (t = "请输入正确的QQ号码");
            break;

          case "kugou":
            n.default.kugou.test(e) || (t = "请输入正确的酷狗ID");
            break;

          case "kuaishou":
            n.default.ks.test(e) || (t = "请输入正确的快手账号");
            break;

          case "zhihu":
            n.default.phone.test(e) || (t = "请输入正确的知乎账号(手机号)");
            break;

          case "phone":
            n.default.phone.test(e) || (t = "请输入正确的手机号");
            break;

          case "weibo":
            e || (t = "请输入正确的微博昵称");
            break;

          default:
            n.default.qq.test(e) || (t = "请输入正确的账号");
        }
        return !t || (wx.showToast({
            title: t,
            icon: "none"
        }), t = "", !1);
    },
    clickGuide: function(e) {
        switch (e.currentTarget.dataset.type) {
          case "kuaishou":
            wx.navigateTo({
                url: "/pages/superMemberGold/webview/webview?type=kuaishou"
            });
            break;

          case "zhihu":
            wx.navigateTo({
                url: "/pages/superMemberGold/webview/webview?type=zhihu"
            });
            break;

          case "kugou":
            wx.navigateTo({
                url: "/pages/superMemberGold/kugouGuide/kugouGuide"
            });
            break;

          case "tencentVideo":
            wx.navigateTo({
                url: "/pages/superMemberGold/tencentVideoGuide/tencentVideoGuide"
            });
        }
    },
    onCancelGet: function() {
        this.setData({
            showConfirm: !1
        });
    },
    onConfirmGet: function() {
        this.setData({
            showConfirm: !1
        }), this.reqGetVip();
    },
    reqGetVip: function() {
        var e = this, t = {
            right: this.data.activeActionCode,
            rightAccount: this.data.getRightAccount
        };
        wx.showLoading({
            title: "领取中..."
        }), a.default.receiveRight(t).then(function(e) {
            wx.hideLoading(), wx.redirectTo({
                url: "/pages/superMemberGold/success/success"
            });
        }).catch(function(t) {
            switch (wx.hideLoading(), t.code) {
              case "2107040361":
              case "20008":
                var i = "黄金版";
                "platinumcard" === e.data.vipType ? i = "白金版" : "silvercard" === e.data.vipType && (i = "白银版"), 
                wx.showModal({
                    title: "温馨提示",
                    content: "您的当前可用预存款不足，无法享受超级会员（".concat(i, "）权益"),
                    showCancel: !1
                });
                break;

              default:
                wx.showModal({
                    title: "温馨提示",
                    content: t.message || t.msg || "请求失败，请稍后再试！",
                    showCancel: !1
                });
            }
        });
    },
    onCancel100min: function() {
        this.setData({
            show100minConfirm: !1
        });
    },
    onConfirm100min: function() {
        this.setData({
            showConfirm: !0,
            show100minConfirm: !1
        });
    }
});